<?php

namespace App\Http\Controllers\Admin;

use App\Models\Balancewithdraw;
/**
 * Description of Userwithdraw
 *
 * @author yonguo
 */
class Userwithdraw extends BaseController{
    
    /**
     * 用户申请提现列表审核
     */
    public function usercommissionwithdrawlist()
    {
       $this->assign([
                'time_begin'=>'',
                'time_end'=>'' 
            ]);
        $query = Balancewithdraw::with('user');
        $queryParams = [];
        $time_begin = $this->request->input('ask_time_begin');
            if ($time_begin) {
                $queryParams['time_begin'] = $time_begin;
                $query = $query->where('ask_for_date', '>=', strtotime($time_begin));
            }

            $time_end = $this->request->input('ask_time_end');
            if ($time_begin) {
                $queryParams['time_end'] = $time_end;
                $query = $query->where('ask_for_date', '<=', strtotime($time_end));
            }
            $this->assign($queryParams);
        $blancewithdraws = $query->orderBy('id')->paginate(20);
        
        $this->assign([
                'blancewithdraws'=>$blancewithdraws,
                'pagination'=>$blancewithdraws->appends($queryParams)->render()
                
            ]);
        return $this->view('admin.user.blankwithdraw');
    }
    
    public function auditblance() {
        $id = intval($this->request->get('id'));
        if ($this->isOnSubmit()) {
            $wdraw = $this->request->post('wdraw');
            if($wdraw['transfer_type']==1)
            {
                $transfer_result = "会员提现,线下转账成功";
            }else
               
            {
                $transfer_result = "会员提现,线上转账成功";
            }
            $wdraw['transfer_status']= 1;
            $wdraw['transfer_result'] = $transfer_result;
           
            if ($id) {
                Balancewithdraw::where('id', $id)->update($wdraw);
            }
            return $this->messager()->message(trans('sysmessage.info save success'))->render();
        }else {
            $this->assign([
                'id'=>$id,
                'transfer_type' => '',
                'transfer_name' => '',
                'transfer_money' => '',
                'transfer_status' => '',
                'transfer_remark' => '',
                'transfer_no' => '',
                'transfer_account_no' => '',
                'transfer_status' => ''
            ]);

            if ($id) {
                $aduit = Balancewithdraw::find($id);
            }

            return $this->view('admin.user.auditblance', compact('aduit'));
        }
    }
}
